var LocationMsgSender = (function(){
    
    var _LocationMsgSender = (function(){}).extend(MsgSender);
    
    _LocationMsgSender.prototype.send = function(cb){
        var _this = this,
            latLng = this.content,
            position = {
                "longitude" : latLng.lng(),
                "latitude" : latLng.lat(),
                'zoom' : latLng.zoom
            };            
            
        var chatGroupEntity = page.chatGroupStore.getItem(_this.chatGroupID);
        var locData = {
            contentType : 'location',                            
            teid : _this.chatGroupID,                
            seq : 0,
            content : JSON.stringify(position),
        };
        
        if(chatGroupEntity.perm.rloc && page.position){
            locData['la'] = page.position.coords.latitude;
            locData['lo'] = page.position.coords.longitude;
        }
        
        //呈现LocationMsg.
        var locMsg = (new ChatLocationMsg(locData, 'right')).render(_this.chatPanel.chatView);
        locMsg.markSending();
        
        var flag = false;
        if(locMsg.canShowReaders()){
            flag = true;
            locMsg.disableShowReaders();
        }
          
        page.biz.sendLocation(this.chatGroupID, latLng, function(msg){
            locMsg.clearSending();
            //将LocationMsg添加到本地缓存.
            page.chatMsgStore.addItem({
                local : true,
                teid : _this.chatGroupID,
                seq : msg['seq'],
                createTime : msg['time'],
                contentType : MsgType.LOCATION,
                from : 'web',
                id : msg['id'],
                content : position,
                user : _this.user
            }); 
            locMsg.updateSeq(msg['seq']).updateMsgTime(msg['time']); 
            locMsg.adjustPos(msg['seq']).chatView.refreshReadCount();
            if(flag){
                locMsg.enableShowReaders();
            }          
            cb && cb(msg);
        }).fail(function(){
            locMsg.markFailed();
            locMsg.$retryBtn.click(function(){
                locMsg.hide();
                _this.send(function(){
                    _this.chatPanel.chatView.$wrapper.scrollToEnd();
                });
                return false;
            });
        });
    };
    
    return _LocationMsgSender;
})();